#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;

struct Homework
{
    int no;
    int deadline;
    int deduction;
};

void sort(Homework homework[], int n)
{
    int most_emergent;
    Homework tmp;
    for (int i = 0; i < n - 1; i++)
    {
        most_emergent = i;
        for (int j = i + 1; j < n; j++)
        {
            if (homework[j].deadline < homework[most_emergent].deadline)
                most_emergent = j;
            else if (homework[j].deadline == homework[most_emergent].deadline && homework[j].deduction > homework[most_emergent].deduction)
                most_emergent = j;
        }
        tmp = homework[i];
        homework[i] = homework[most_emergent];
        homework[most_emergent] = tmp;
    }
}

int main(void)
{
    int n, time, deducted_point;
    cin >> n;
    while (n != 0)
    {
        Homework* homework = new Homework[n];
        for (int i = 0; i < n; i++)
        {
            homework[i].no = i + 1;
            cin >> homework[i].deadline;
        }

        for (int i = 0; i < n; i++)
            cin >> homework[i].deduction;

        sort(homework, n);

        time = 1;
        deducted_point = 0;
        for (int i = 0; i < n; i++)
        {
            if (time <= homework[i].deadline)
            {
                cout << homework[i].no << ' ';
                time++;
            }
            else
                deducted_point += homework[i].deduction;
        }
        cout << endl;
        cout << deducted_point << endl;
        delete[] homework;
        cin >> n;
    }
    return 0;
}